Skip to content

Check the batch action is not running when removing, cascade events - #687

Merged
jakub-id merged 3 commits into
mainfrom
lock-scheduled-task
Jul 23, 2026
Merged

Check the batch action is not running when removing, cascade events#687
jakub-id merged 3 commits into
mainfrom
lock-scheduled-task

Conversation

@jakub-id

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 23, 2026 19:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens scheduler/batch-action lifecycle handling by adding row-level locking for scheduled-task mutations, preventing deletion while a batch action is still queued/processing, and cleaning up batch-action-related events when a batch action is removed.

Changes:

  • Add FOR UPDATE scheduled-task fetches and use them to revalidate/serialize mutations (API mutations + stuck-task recovery).
  • Add queries to detect/delete batch-action events by taskId and enforce a 409 Conflict when deleting an in-progress batch action.
  • Extend unit/integration tests and OpenAPI to cover the new behaviors.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
broker/test/scheduler/db/schedrepo_test.go Adds DB-level tests for active-event detection, event cleanup, and rollback behavior.
broker/sqlc/sched_query.sql Introduces GetScheduledTaskByIdForUpdate query for row-locking scheduled_task.
broker/sqlc/event_query.sql Adds queries to detect active batch-action events and delete batch-action events by taskId.
broker/scheduler/service/scheduler.go Revalidates “stuck” tasks under row lock before rescheduling/disabling.
broker/scheduler/service/scheduler_test.go Updates scheduler tests to exercise revalidation/skip paths with updated_at + row locking.
broker/scheduler/db/repo.go Exposes new repo methods for row-lock fetch and batch-action event checks/deletes.
broker/scheduler/api/api_handler.go Uses row-locking + active-event checks on delete; refactors batch-action mutations into a shared helper.
broker/scheduler/api/api_handler_test.go Updates mocks and adds coverage for 409 Conflict + error paths.
broker/oapi/open-api.yaml Documents 409 Conflict response for deleting an in-progress batch action.
Comments suppressed due to low confidence (1)

broker/scheduler/db/repo.go:124

  • events.New() is not defined in the non-generated broker/events package, so this call likely won’t compile after sqlc generation. Call the sqlc query method on a zero-value events.Queries instead.
func (r *PgSchedRepo) DeleteBatchActionEvents(ctx common.ExtendedContext, taskID string) error {
	return events.New().DeleteBatchActionEvents(ctx, r.GetConnOrTx(), taskID)
}

Comment thread broker/scheduler/db/repo.go
Comment thread broker/scheduler/api/api_handler.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@jakub-id
jakub-id merged commit 80a1cdd into main Jul 23, 2026
7 of 9 checks passed
@jakub-id
jakub-id deleted the lock-scheduled-task branch July 23, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants